package com.gwcd.myapplication;

import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard;
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;

import android.content.Intent;

import androidx.test.core.app.ActivityScenario;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;

import com.gwcd.myapplication.ui.SeActivity;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class SeActivityTest {

    @Before
    public void launchActivity() {
        Intent intent = new Intent();
        intent.setClass(getApplicationContext(), SeActivity.class);
        intent.putExtra("handle", 978234);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ActivityScenario.launch(intent);
    }

    @Test
    public void testInteger() {
        performOperation(123);
    }
    @Test
    public void testDouble() {
        performOperation(123.31887);
    }

    private void performOperation(double input) {
        onView(withId(R.id.et_input)).perform(typeText(String.valueOf(input)), closeSoftKeyboard());
        onView(withId(R.id.btn_commit)).perform(click());
        onView(withId(R.id.tv_result)).check(matches(withText(String.valueOf(input))));
    }
}
